<div id="pick-file-btn-container">
    <button id="pick-file-btn" class="btn btn-default">选择文件</button>
</div>

<style>
    #pick-file-btn-container {
        position: absolute;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        text-align: center;
        background: #f0f0f0;
    }

    #pick-file-btn {
        position: absolute;
        top: 50%;
        left: 50%;
        margin-top: -25px;
        margin-left: -50px;
        height: 50px;
        width: 100px;
    }
</style>

<script>
    var uploader = new plupload.Uploader({
        runtimes: 'html5,flash,silverlight,html4',
        browse_button: 'pick-file-btn',
        container: document.getElementById('pick-file-btn-container'),
        chunk_size: '1mb',
        max_file_size: '100mb',
        url: '<?php echo base_url('api/uploadFile')?>',
        resize: {
            width: 1920,
            height: 1080,
            quality: 70
        },
        multipart_params: {},
        multi_selection: false,
        unique_names: true,
        file_data_name: "file",
        flash_swf_url: '<?php echo base_url('public/libraries/plupload-2.1.1/Moxie.swf') ?>',
        silverlight_xap_url: '<?php echo base_url('public/libraries/plupload-2.1.1/Moxie.xap') ?>',
        init: {
            FilesAdded: function (up, files) {
                uploader.start();
            },

            BeforeUpload: function (up, file) {
                up.settings.multipart_params.file_ori_name = file.name;
                showProgressNoty();
            },

            UploadProgress: function (up, file) {
                changeProgressNoty(file.percent);
            },

            Error: function (up, err) {
                noty({type: 'error', text: 'err.code' + ' - ' + err.message});
            },

            FileUploaded: function (up, file, info) {
                closeProgressNoty();
                try {
                    var rsp = $.parseJSON(info.response);
                    noty({type: rsp.type, text: rsp.message, callback: {
                        afterClose: function () {
                            switch (rsp.type) {
                                case 'success':
                                    try {
                                        var parent = window.parent;
                                        $(parent.document).find('#' + parent.TheFieldName).val(rsp.data.absoluteUrl);
                                        parent.ActiveEditor.windowManager.close();
                                        location.reload();
                                    } catch (e) {

                                    }
                                    break;
                                default:
                                    break;
                            }
                        }
                    }});
                } catch (ex) {
                    noty({type: 'error', text: '发生内部错误，请联系管理员'});
                    throw ex;
                }
            }
        }
    });
    uploader.init();
</script>